package com.example.courtcounter;

import static com.example.courtcounter.R.*;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;

import com.example.courtcounter.R.id;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends AppCompatActivity {

    Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout.activity_main2);
        GridView listView = findViewById(R.id.gridview);
        ProgressBar bar = findViewById(R.id.progressBar);

            List<String> mylist=new ArrayList<>(100);
            for(int i=1;i<=100;i++){
               mylist.add("Item"+i);
            }

        ListAdapter adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);///适配器更改
        listView.setAdapter(adapter);
        //listView.setEmptyView(findViewById(R.id.nodata));

        Handler handler = new Handler(Looper.myLooper()) {
            @Override
            public void handleMessage(@NonNull Message msg) {
                if (msg.what == 7) {
                    Bundle bundle = (Bundle) msg.obj;
                    ArrayList<String> list2 = bundle.getStringArrayList("mylist");
                    ListAdapter adapter = new ArrayAdapter<String>(MainActivity2.this, android.R.layout.simple_list_item_1, list2);
                    listView.setAdapter(adapter);
                    //切换显示
                    listView.setVisibility(View.VISIBLE);
                    bar.setVisibility(View.GONE);

                }
                super.handleMessage(msg);
            }
        };
        Thread t = new Thread(new MyTask(handler));
        t.start();
    }
}